<?php
class Ourworks extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->helper(array('url','authentication_helper'));
		$this->load->library('user_agent');
		$this->load->model(array('ourworks_model','ourwork_items_model'));
	}

	public function index()
	{
		$rs = $this->ourworks_model->get_our_works();
		$data['ourworks'] = $rs->result_array();
		if (empty($data['ourworks']))
		{
		show_404();
		}
	
		$data['page_title'] = ucfirst('Our Works'); // Capitalize the first letter
		
		//replace to default file if not exists
		for ($i = 0; $i < count($data['ourworks']); $i++) {
    		if (!isValidURL(base_url($data['ourworks'][$i]['image_url']))) {
				$data['ourworks'][$i]['image_url'] = 'resources/web/images/alt_logo_ourwork.png';
			}
		}
		
		$is_mobile = $this->agent->is_mobile();
		//$is_mobile = true; //uncomment for mobile version
	
		if (!$is_mobile) {
		$this->load->view('web/templates/header', $data);
		$this->load->view('web/ourworks', $data);
		$this->load->view('web/templates/footer', $data);
		} else {
		$this->load->view('mobile/templates/header', $data);
		$this->load->view('mobile/ourworks.php', $data);
		$this->load->view('mobile/templates/footer', $data);
		}
	}
	
	public function ourwork_item($type)
	{
		$rs = $this->ourwork_items_model->get_items($type);
		$data['items'] = $rs->result_array();
		if (empty($data['items']))
		{
		show_404();
		}
		
		$data['type'] = $type;
		
		if ($type == 'casestudy') {
		  //replace to default file if not exists
		  for ($i = 0; $i < count($data['items']); $i++) {
			if (!isValidURL(base_url($data['items'][$i]['image_url']))) {
				$data['items'][$i]['image_url'] = 'resources/web/images/alt_logo_casestudies1.png';
			}
		  }
		}
		
				
		if ($type == 'client')
		{
			$type = 'Client';
		} else if ($type == 'casestudy')
		{
			$type = 'Case Studies';
		}
		else if ($type == 'portfolio')
		{
			$type = 'Portfolio';
		}
		$data['page_title'] = ucfirst($type); // Capitalize the first letter
		
		$is_mobile = $this->agent->is_mobile();
		//$is_mobile = true; //uncomment for mobile version
	
		if (!$is_mobile) {
		$this->load->view('web/templates/header', $data);
		$this->load->view('web/ourwork_item.php', $data);
		$this->load->view('web/templates/footer', $data);
		} else {
		$this->load->view('mobile/templates/header', $data);
		$this->load->view('mobile/ourwork_item.php', $data);
		$this->load->view('mobile/templates/footer', $data);
		}
	}
}
